Coding Games: Tips and Tricks to Master the Key Concepts of Coding by Robert C. Matthews

Coding Games: Tips and Tricks to Master the Key Concepts of Coding by Robert C. Matthews

Author:Robert C. Matthews [Matthews, Robert C.]
Language: eng
Format: azw3
Published: 2020-11-02T00:00:00+00:00


List

HashMap

And so on.

We’ve talked about the first two on the list, so let’s briefly touch on HashMaps.

What are Hash Maps? How best to highlight their functions than to, as I always love to do, first see how they are applied. Imagine you are an experienced full stack developer called in to troubleshoot a retail e-commerce website which has been having some problems with bugs and such. The first you do of course is to run the software on your IDE (more on that later). Upon running the code, you begin noticing some arrangements such as:

“Shoes” -> “Oxfords”, “Brogues”

“Utensils” -> “Spoons”, “Forks”, “Knives”

“Knives” -> “Japanese”, “Western”

“Shirts” -> “formal”, “casual”

If you see something like that, don’t be afraid. And it’s not the problem (unless it is).

Let’s take a further look at this highlighted example.

One thing you notice here is that there are “general” names of items on the left, which point to more specific ones on the right. This pairing up of values is in the coding circle as a Key/Value pair.

The “key” in these instances are the general items - shoes, shirts and such, and value here means the specific items from the general list.

This pairing arrangement is possible due to a HashMap data structure! This is a very useful concept that is applied to almost every retail website! For example, if you want to buy something on Amazon right now. Let’s say a phone. Where does the home page of the website first take you? To the electronics section! Next, you choose the phone maker, (also making use of a hash map), where you fill your specifications and such. This similar application of HashMap has tremendous potentials in our manipulation and application of data variables.

While the representation of HashMaps I gave up there looks rather fancy, the truth is, HashMaps are slightly more complex than that.

For example, here’s how the HashMap of the program I showed you would look like, in Java code.

Map<String, List<String>> Shoes = new HashMap<String, List<String>>();

shoes.put("Oxfords", new ArrayList(Arrays.asList("Brogues", "Loafers", "Monkstraps")));

Whoa, right?

That’s a lot of brackets. Let’s break it down a bit.

As you know, the HashMap data structure is used to store key/value pairs. In this selected example, our key was shoes and the value pairs are the oxfords and such. Remember that the data type is a string. And because the collection of data is similar, they are defined by arrays. Now we get to an interesting part. Say a new type of shoes was just shipped in and we want to add this new option to our web app. What is to be done?

Traditionally, the “old” method would be to rewrite the code repeatedly, which is mindless drudgery and pretty much depressing. Instead what we do is create a new list of Arrayed data, insert it in our HashMap, and voila, done!



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.